<?php

/**
 * Created by PhpStorm.
 * User: wen
 * Date: 2017/6/21
 * Time: 9:43
 */
namespace V1;
use Util\LogUtil;

class Browse extends \ResourceClass
{
    public $isActive = true;
    public $remark = '文章浏览累加';
    public function post(array $req, array $post, &$result) {

        if (!array_key_exists('uid',$req)) {
            return 'uid not null';
        }
        $data = base64_decode($post['payload']);
        @parse_str($data, $data);
        if(!isset($data['article_id'])) {
            return '文章id 不能为空';
        }
        try{
            $article_cls = new \Orm\Article\ArticleClass();
            $article_cls ->loadById($data['article_id']);
            $article_cls['reading_times'] = $article_cls['reading_times']+1;
            $article_cls -> update();
            $result = array('reading_times'=>$article_cls['reading_times']);
        }catch (\Exception $e){
            throw new \Exception($e->getMessage());
        }
    }

}